#pragma once

#include <Common/Common.h>
#include "GcpProxy.h"
#include "GcpClientEvent.h"

struct IGcpConnectorCallback
{
    virtual IGcpHandler* OnGcpConnected(CGcpProxyPtr spProxy) = 0;
    virtual void OnGcpConnectError(Int32 nError) = 0;
};

class CGcpConnector : public ITCPConnector2Callback, public IMessageDispatcher
{
public:
    CGcpConnector(CEventEngine *pEngine);
    virtual ~CGcpConnector();

public:
    Bool Connect(const CSocketAddr &server, Int32 nTimeout, IGcpConnectorCallback *pCallback);

protected:
    virtual void OnConnected();
    virtual void OnConnectFailed(Int32 nError);
    virtual void OnConnectTimeout();

    virtual void DispatchMessage(CClientEvent *pClientEvent, void *pMsg);

protected:
    IGcpConnectorCallback*          m_pCallback;
    CTCPConnector2                  m_connector;
    CEventEngine*                   m_pEngine;
};
